<!DOCTYPE HTML>
<script src="../../../../resources/js-test.js"></script>
<style>
html, body {
 margin: 0;
}
body {
  height: 1000px;
}
#target {
  width: 50px;
  height: 50px;
  margin: 5px 0px 0px 5px;
}
</style>
<iframe frameborder=0 id="target" src="resources/event-delegator.html"></iframe>
<div id=console></div>
<script>
var event;
var windowScrollOffset = {
    x: 0,
    y: 3
};
var frameScrollOffset = {
    x: 2,
    y: 7
};
window.scrollTo(windowScrollOffset.x, windowScrollOffset.y);
var frameRect = target.getBoundingClientRect();
var pointInFrame = {
    x: frameRect.width / 2,
    y: frameRect.height / 2
};
var pointInWindow = {
    x: frameRect.left + pointInFrame.x,
    y: frameRect.top + pointInFrame.y
};

var eventReceived = {};

function onEventInFrame(e) {
    debug("Received " + e.type + " in child frame");
    event = e;
    eventReceived[e.type] = true;
    shouldBe("event.screenX", "pointInWindow.x");
    shouldBe("event.screenY", "pointInWindow.y");
    shouldBe("event.clientX", "pointInFrame.x");
    shouldBe("event.clientY", "pointInFrame.y");
    shouldBe("event.pageX", "pointInFrame.x + frameScrollOffset.x");
    shouldBe("event.pageY", "pointInFrame.y + frameScrollOffset.y");
}

description("Verifies that a tap occurring in a scrolled iframe has the correct co-ordinates");

if (window.eventSender) {
    jsTestIsAsync = true;
    target.onload = function() {
        target.contentWindow.scrollTo(frameScrollOffset.x, frameScrollOffset.y);

        debug("Sending GestureTapDown to " + pointInWindow.x + "," + pointInWindow.y);
        eventSender.gestureTapDown(pointInWindow.x, pointInWindow.y);

        debug("Sending GestureShowPress");
        eventSender.gestureShowPress(pointInWindow.x, pointInWindow.y);

        debug("Sending GestureTap");
        eventSender.gestureTap(pointInWindow.x, pointInWindow.y);

        shouldBeTrue("eventReceived.mousemove");
        shouldBeTrue("eventReceived.mousedown");
        shouldBeTrue("eventReceived.mouseup");
        shouldBeTrue("eventReceived.click");
        setTimeout(finishJSTest, 0);
    }
} else {
    debug("This test requires eventSender");
}
</script>
